perf(mpsc): use a segmented unbounded queue - #232
Closed
tisonkun wants to merge 3 commits into
Closed
Conversation
This was referenced Aug 31, 2026
Member
Author
|
Shelved in favor of main's simpler batched queue. The measured workload-dependent gains do not justify adopting the segmented queue's additional complexity at this time. The branch and PR history are retained for reference. Follow-up #295 starts from current main and moves retired batch and segment-directory deallocation outside the shared state lock, with a separate main-versus-change benchmark comparison. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Unpinfor pinned payloads.Part of #209.
Design Notes
The producer reserving a block's final slot installs its successor before publishing that slot. FIFO consumption then establishes that every producer using the old block has finished, allowing the unique consumer to reclaim it without a shared head CAS. Each block has up to 31 slots, reduced in power-of-two laps to keep ordinary slot storage within 32 KiB; oversized payloads use one slot per block. Empty channels allocate no message blocks, and drained channels retain at most one block. Block metadata and slots currently use separate allocations.
Publication, receiver registration, and final-sender disconnection participate in one sequentially consistent order to prevent lost notifications. Waker clone, drop, and wake callbacks run outside locks; receiver teardown removes the registered waker before draining messages. Sending and receiving may wait for an in-progress producer, and initialization and notification use internal mutexes. Exact Crossbeam provenance and the Apache-2.0 license option are recorded in the source and
LICENSE.The following comparison uses main
7092326c93b9d2cb91d7b80d1b8100ae1325ed57and PR6d827e4, compiled into the same benchmark executable on an Apple M4 Max, macOS 26.6.2, rustc 1.99.0-nightly (3d6c19bb9). Numbers are the median of five round medians with randomized implementation order, 100 samples per case, 1,000 iterations per microbenchmark sample, and one batch per throughput sample. The main library source is unchanged; a temporary path dependency supplies the baseline adapter. Peers are Tokio 1.53.1, async-channel 2.5.0, Flume 0.12.0, and Crossbeam 0.5.17. Crossbeam participates only in synchronous cases. Lower elapsed time is better; “best peer” means the fastest of these measured peers for that workload.The results favor ready-message and contended asynchronous workloads but show material construction, one-shot, inline-payload, and native-thread regressions. They do not establish a uniform improvement over main. The full comparison covers all 21 existing unbounded workloads plus the two lifecycle cases.
Validated with
cargo x teston stable and Rust 1.86.0,cargo x check,cargo x lint,cargo x bench --no-run, benchmark smoke execution, and the fullcargo x miriworkflow. MPSC concurrency tests additionally pass Miri seeds 1 through 3 with strict provenance and symbolic alignment checks.cargo semver-checksagainst current main passes all 223 applicable checks.GitHub CI also passes the stable/MSRV test matrix on Linux, macOS, and Windows, the quality/feature/benchmark checks, and the Miri workflow with seeds 0 through 3.